package com.tyao.mybatis;
/**
 * Spring+Spring MVC+MyBatis示例项目
 * @author 边城飘雪
 * @email mymb52@163.com
 * @date 2018-02-25
 */
import java.io.UnsupportedEncodingException;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import org.mybatis.generator.internal.util.StringUtility;

/**
 * 主要是自定义注释生成
 * @author mymb52
 *
 */
public class MyCommentGenerator extends org.mybatis.generator.internal.DefaultCommentGenerator {

    public MyCommentGenerator() {
	super();
	// TODO Auto-generated constructor stub
    }

    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
	    IntrospectedColumn introspectedColumn) {
	if (introspectedColumn.getRemarks() != null && !introspectedColumn.getRemarks().equals("")) {
	    field.addJavaDocLine("/**");
	    field.addJavaDocLine(" * " + introspectedColumn.getRemarks());
	    // addJavadocTag(field, false);
	    field.addJavaDocLine(" */");
	}
    }

    @Override
    public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	topLevelClass.addJavaDocLine("/**"); //$NON-NLS-1$

	String remarks = introspectedTable.getRemarks();
	String[] remarkLines = remarks.split(System.getProperty("line.separator")); //$NON-NLS-1$
	for (String remarkLine : remarkLines) {
	    topLevelClass.addJavaDocLine(" *   " + remarkLine); //$NON-NLS-1$
	}
	topLevelClass.addJavaDocLine(" *"); //$NON-NLS-1$
	addJavadocTag(topLevelClass, true);
	topLevelClass.addJavaDocLine(" */"); //$NON-NLS-1$
    }
}
